﻿@model IDictionary<string, object>
<script type="text/javascript">
    $(function () {

        $("#size li").click(function () {
            $("#size li").removeClass("tb-selected");
            $(this).addClass("tb-selected");
            $("#hdsizeno").val($(this).attr("data-value"));

            GetSTOCKS();
        });
        $("#color li").click(function () {
            $("#color li").removeClass("tb-selected");
            $(this).addClass("tb-selected");
            $("#hdcolorno").val($(this).attr("data-value"));

            GetSTOCKS();
        });
        $(".increase").click(function () {

            if (CheckGoCount()) {
                var stock = parseInt($("#gstock").html());
                var count = parseInt($("#J_IptAmount").val());
                if (count > 0 && count < stock) {
                    count++

                    $("#J_IptAmount").val(count);
                } else if (count <= 0) {
                    $("#J_IptAmount").val(1);

                }
            }
        });
        $(".decrease").click(function () {

            if (CheckGoCount()) {
                var stock = parseInt($("#gstock").html());
                var count = parseInt($("#J_IptAmount").val());
                if (count > 1 && count <= stock) {
                    count--

                    $("#J_IptAmount").val(count);
                } else if (count <= 1) {
                    $("#J_IptAmount").val(1);

                }
            }
        });
        $("#J_Favorite").click(function () {
            $.post("/Collection/AddCollect",
                { "shopNo": $("#hdShopNO").val(), "gNo": $("#hdGNO").val() },
                 function (data) {

                     if (data.ResultCode == "00") {


                     } else {


                     }
                 }, "json");
        });
        $("#J_LinkAdd").click(function () {

            $.post("/Order/AddCart",
            { "gID": $("#hdGID").val(),"gItemID": $("#hdItemID").val(),"count": $("#J_IptAmount").val(),"shopNo": $("#hdShopNO").val() },
                 function (data) {
                    
                     if (data.ResultCode == "00") {


                     } else {


                     }
                 }, "json");
        });
    });
    function CheckGoCount()
    {
        if(isNaN($("#J_IptAmount").val())){
         alert("请输入数字");
         return false;
         }
          var count = parseInt($("#J_IptAmount").val());
          if (count<=0)
        {
            alert("请输入正整数");
            return false;
        }
        var stock = parseInt($("#gstock").html());
        if (count > stock) {
            alert("库存不足");
            return false;
        }
        return true;
    }
    function GetSTOCKS() {
        var s = $("#hdsizeno").length;
        var c = $("#hdcolorno").length;
       
        if (s > 0 && c > 0) {

            if ($("#hdsizeno").val() == "" || $("#hdcolorno").val() == "") {

                return false;

            }
        }
        else if (s > 0) {

            if ($("#hdsizeno").val() == "") {
                return false;
            }
        } else if (c > 0) {

            if ($("#hdcolorno").val() == "") {
                return false;
            }
        } else {

            return false;
        }


        $.post("/Detail/GetStock",
                { "GNO": $("#hdGNO").val(), "SizeNo": $("#hdsizeno").val(), "ColorNo": $("#hdcolorno").val() },
                 function (data) {
                    
                     if (data.ResultCode == "00") {

                         $("#J_StrPrice").html(data.price);
                         $("#hdItemID").val(data.itemID);
                         $("#hdItemNO").val(data.itemNo);
                         $("#gstock").html(data.Stock);
                     } else {


                     }
                 }, "json");
    }       
</script>
<div class="tb-skin tb-naked">
    <p class="tb-note-title">
        请选择您要的商品信息<b class="J_PanelCloser">关闭</b></p>
    <div class="tb-sku">
     @if (Model != null)
     {
        if (Model["size"] != null)
        {
            <dl class="tb-prop tb-clearfix">
                <!-- 新版服饰使用 -->
                <dt class="tb-h">尺码</dt>
                <dd>
                    <ul id="size" data-property="尺码" class="tb-clearfix J_TSaleProp  ">
                        @foreach (var item in (List<Enter.Mvc.Mall.Model.Product.SizeModel>)Model["size"])
                        {
                 
                            <li data-value="@item.SizeNO"><a href="#;"><span>@item.SizeName</span></a></li>
                        }
                        <input id="hdsizeno" value="" type="hidden" />
                    </ul>
                </dd>
            </dl>
        }
        if (Model["color"] != null)
        {
            <dl class="tb-prop tb-clearfix">
                <!-- 新版服饰使用 -->
                <dt>颜色分类</dt>
                <dd>
                    <ul id="color" data-property="颜色分类" class="tb-clearfix J_TSaleProp tb-img  ">
                        @foreach (var item in (List<Enter.Mvc.Mall.Model.Product.ColorModel>)Model["color"])
                        {
                          
                            <li  data-value="@item.CNo" title="@item.CName">
                                @if (string.IsNullOrEmpty(item.imgUrl))
                                {
                                    <a href="#;"><span>@item.CName</span> </a>
                                }
                                else
                                { 
                                    <a href="#;" style="background: url(&quot;@item.imgUrl&quot;) no-repeat scroll center center transparent;">
                                        <span>@item.CName</span> </a>
                                }</li>
                        }
                        <input id="hdcolorno" value="" type="hidden" />
                    </ul>
                </dd>
            </dl>
        }
     }
        <dl class="tb-amount tb-clearfix">
            <dt>数量</dt>
            <dd id="J_Amount">
                <span class="tb-amount-widget" id="J_AmountWidget">
                    <input id="J_IptAmount" class="tb-text" value="1" maxlength="8" title="请输入购买量" type="text">
                    <span class="increase"></span><span class="decrease"></span></span>件<em id="J_EmStock">(库存<span
                        id="gstock"></span>件)</em>
            </dd>
        </dl>
    </div>
    <dl id="J_DlChoice" class="tb-choice tb-clearfix tb-h">
        <dt>请选择：</dt>
        <dd class="tb-h">
            <em>"尺码"</em></dd>
    </dl>
    <div class="tb-action tb-clearfix">
        <div class="tb-btn-buy">
            <a id="J_LinkBuy" href="#" data-addfastbuy="true" title="点击此按钮，到下一步确认购买信息。">立刻购买<b></b></a>
        </div>
        <div class="tb-btn-add">
            <a href="#;" title="加入购物车" id="J_LinkAdd">加入购物车<b></b></a></div>
    </div>
</div>

